package com.hqq.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Base64;

/**
 * CodeUtil
 * 编码解码帮助类
 * Created by heqianqian on 2017/7/19.
 */
public class CodeUtil {

    private static final Logger LOGGER = LoggerFactory.getLogger(CodeUtil.class);

    /**
     * 加密URL地址
     */
    public static String encodeURL(String url) {
        String target = null;
        try {
            target = URLEncoder.encode(url, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            LOGGER.error(e.getMessage());
        }
        return target;
    }

    /**
     * 解密URL地址
     */
    public static String decodeURL(String url) {
        String result = null;
        try {
            URLDecoder.decode(url, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            LOGGER.error(e.getMessage());
        }
        return result;
    }

}
